//
//  HTTPSecssionManger.m

#import "HTTPSecssionManger.h"
#import "AFNetworking.h"
@implementation HTTPSecssionManger

+(HTTPSecssionManger *)sharedManager{
    static HTTPSecssionManger *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[HTTPSecssionManger alloc]init];
    });
    return instance;
}

-(void)GET:(NSString *)url params:(id)params result:(ResultBlock)block{
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager GET:url parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (block) {
            block(responseObject,nil);
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"error:%@",error);
        if (block) {
            block(nil,error);
        }
    }];
    
}

-(void)POST:(NSString*)url params:(id)params result:(ResultBlock)block
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager GET:url parameters:params success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if (block) {
            block(responseObject,params);
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        NSLog(@"error:%@",error);
        if (block) {
            block(nil,error);
        }
    }];
}

@end

